import {Component, OnInit} from '@angular/core';
import {FormBuilder, FormGroup} from '@angular/forms';
import {SharedModule} from '../shared.module';
import {MODAL_WIDTH} from '../../const'
import {Charge} from '../../types/resp/Charge';

@Component({
  selector: 'charge-view',
  imports: [
    SharedModule
  ],
  templateUrl: './charge-view.component.html',
  standalone: true
})
export class ChargeViewComponent implements OnInit {
  chargeForm!: FormGroup;
  isVisible: boolean = false
  title: string = '收费信息详情'
  modalWidth: string = MODAL_WIDTH

  constructor(
    private fb: FormBuilder
  ) {}

  ngOnInit(): void {
    this.chargeForm = this.fb.group({
      buildingName: [''],
      roomNumber: [''],
      chargeType: [undefined],
      billingCycle: [''],
      billingStartDate: [''],
      billingEndDate: [''],
      amount: [0],
      lateFee: [0],
      dueDate: [''],
      paymentDate: [''],
      paymentStatus: [undefined],
      createTime: [''],
      modifyTime: [''],
    })
  }

  onBack() {
    this.isVisible = false
  }

  display(charge: Charge) {
    this.isVisible = true
    this.chargeForm.patchValue(charge);
    this.chargeForm.disable();
  }
}
